//
//  ZWNetWorkTools.m
//  使用OC去封装一个工具类
//
//  Created by xue-iOS-work on 16/8/30.
//  Copyright © 2016年 xue. All rights reserved.

#import "ZWNetWorkTools.h"
#define successParameter NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject
#define failureParameter NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error
@implementation ZWNetWorkTools
+(instancetype)sharedTools
{
    static ZWNetWorkTools * instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc]init];
        instance.responseSerializer.acceptableContentTypes = [instance.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
        instance.responseSerializer.acceptableContentTypes = [instance.responseSerializer.acceptableContentTypes setByAddingObject:@"text/plain"];
    });
    return instance;
}
-(void)reques:(HttpMethod)method urlstring:(NSString*)urlstring parameters:(id)parameters completion:(void(^)(id respose ,NSError*error))completion{
    
    void(^success)(successParameter) =^(successParameter) {
        completion(responseObject,nil);
    };
    void(^failure)(failureParameter) = ^(failureParameter) {
        completion(nil,error);
    };
    if(method == HttpMethodPost)
    {
        //发送post请求
        [self POST:urlstring parameters:parameters progress:nil success:success failure:failure];
    }else if (method == HttpMethodGet)
    {
        [self GET:urlstring parameters:parameters progress:nil success:success failure:failure];
        
    }
}
@end
